package com.codrim.cs.data.server.dao.realtime;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 计算实时数据的计算辅助类,主要是累加数据用 Created by Liang.Zhuge on 09/08/2017.
 */
class RealTimeDataHelper {
    private Map<RealTimeKey, RealTimeData> map = new HashMap<>();

    void addClicks(RealTimeKey key, int value) {
        getData(key).addClicks(value);
    }

    void addUClicks(RealTimeKey key, int value) {
        getData(key).addUClicks(value);
    }

    void addGrossConversions(RealTimeKey key, int value) {
        getData(key).addGrossConversions(value);
    }

    void addScrubConversions(RealTimeKey key, int value) {
        getData(key).addScrubConversions(value);
    }

    private RealTimeData getData(RealTimeKey key) {
        return map.computeIfAbsent(key, RealTimeData::new);
    }

    List<RealTimeData> data() {
        List<RealTimeData> result = new ArrayList<>();
        result.addAll(map.values());
        return result;
    }
}
